package com.tungse.vthread;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

/**
 * @Author : Tungse
 * @Date: 2025/8/14 17:24
 * @Description:
 */
public class EchoClient {

    public static void main(String[] args) throws IOException {
        String hostName = "localhost";
        int port = 8090;

        Socket socket = new Socket(hostName, port);

        PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
        BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
        String userInput;
        while ((userInput = stdIn.readLine()) != null) {
            out.println(userInput);
            System.out.println("echo: " + in.readLine());
            if (userInput.equals("bye")) {
                break;
            }
        }
    }
}
